// See the Electron documentation for details on how to use preload scripts:
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
import { contextBridge, ipcRenderer } from 'electron';
contextBridge.exposeInMainWorld('electron', {
  sendMessage: (channel: string, data: any) => {
    ipcRenderer.send(channel, data);
  },
  receiveMessage: (channel: string, func: (event: any, ...args: any[]) => void) => {
    ipcRenderer.on(channel, func);
  },

  receiver: {} as any,

  sendRequest: async function (channel: string, data: any) {
    if (!this.receiver[channel]) {
      ipcRenderer.on(channel, (event: any, args: any) => {
        this.receiver[channel](args);
      });
    }
    return new Promise((resolve, reject) => {
      this.receiver[channel] = (arg2: any) => {
        resolve(arg2);
      };
      ipcRenderer.send(channel, data);
    });
  },

  selectFile: (sliceMinSize: number, sliceSize: number) => {
    ipcRenderer.send("select-file", { sliceMinSize, sliceSize });
  },

  goback: (second: number) => {
    ipcRenderer.send("goback", second);
  }
});
